<%--
  Created by IntelliJ IDEA.
  User: Tang'ya'kang
  Date: 2023/5/17
  Time: 22:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Cart</title>
</head>
<%@ include file="head.jsp"%>
<script>
    $(function () {
        $(".count").change(function () {
            location.href="./cartServlet?action=Update&id="+$(this).attr("id")+"&count="+$(this).val();
        });
    });
</script>
<body>
<div class="card">
    <div class="card-body">
        <h5 class="card-title" align="center">购物车</h5>
        <div class="card-body">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">商品名称</th>
                    <th scope="col">数量</th>
                    <th scope="col">单价</th>
                    <th scope="col">金额</th>
                    <th scope="col">操作</th>
                </tr>
                </thead>
                <c:if test="${not empty sessionScope.cart.map}">
                    <tbody>
                    <c:forEach items="${sessionScope.cart.map}" var="items" varStatus="status">
                        <tr>
                            <th scope="row">${status.count}</th>
                            <td>${items.value.name}</td>
                            <td><input type="text" value="${items.value.count}" width="80px" class="count" id="${items.key}"></td>
                            <td>${items.value.price}</td>
                            <td>${items.value.priceTocal}</td>
                            <td><a href="./cartServlet?action=DeleteById&id=${items.key}">删除</a></td>
                        </tr>
                    </c:forEach>
                    <tr>
                        <th scope="row"></th>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td><a href="./cartServlet?action=Clear" class="badge badge-success">清空购物车</a></td>
                    </tr>
                    </tbody>
                    <tbody>
                        <tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td colspan="4"><div>购物车中共有${sessionScope.cart.countTocal}件物品  总金额 ${sessionScope.cart.priceTocal} 元 &nbsp;&nbsp;&nbsp;<a href="./orderServlet?action=CreateOrder">去结账</a></div></td>

                        </tr>
                    </tbody>
                </c:if>

                <c:if test="${empty sessionScope.cart.map}">
                    <tbody>
                    <tr>
                        <th scope="row" colspan="6" align="center"><a href="./index.jsp">您的购物车空空如也，快和小伙伴一起去购物</a></th>
                    </tr>
                    </tbody>
                </c:if>
            </table>

        </div>

    </div>
    <%@ include file="Foot.jsp"%>
</div>

</body>
</html>
